
package net.badcurrent.ldapodm.test.integration;

import org.springframework.ldap.support.DistinguishedName;
import net.badcurrent.ldapodm.ldap.DistinguishedNameFactory;

import javax.naming.directory.Attributes;
import javax.naming.NamingException;

public class UserDistinguishedNameFactory implements DistinguishedNameFactory {
    public DistinguishedName generateDistinguishedNameFromInstance(Object o) {
        User user = (User) o;
        return new DistinguishedName("cn=" + user.getFirstName() + " " + user.getLastName());
    }

    public DistinguishedName generateDistinguishedNameFromAttributes(Attributes attributes) {
        String givenName;
        String sn;
        try {
            givenName = (String) attributes.get("givenName").get();
            sn = (String) attributes.get("sn").get();
        } catch (NamingException e) {
            throw new net.badcurrent.ldapodm.NamingException(e);
        }
        return new DistinguishedName("cn=" + givenName + " " + sn);
                
    }
}
